package com.oocl.homework.format.data;

import java.util.Set;
import java.util.TreeSet;

import com.oocl.homework.format.moel.Customer;
import com.oocl.homework.format.moel.DateComparator;
import com.oocl.homework.format.moel.IdComparator;

public class CustomerDaoImpl implements CustomerDao{
	
	private static Set<Customer> customers;
	
	
private static CustomerDaoImpl customerDaoImpl;
	
	
	
	public static CustomerDaoImpl getInstance(){
		if(customerDaoImpl==null){
			synchronized (CustomerDaoImpl.class) {
				if (customerDaoImpl==null) {
					customerDaoImpl = new CustomerDaoImpl();
				}
			}
		}
		return customerDaoImpl;
	}
	
	private CustomerDaoImpl() {
		customers = new TreeSet<>(new IdComparator());
	}
	
	

	@Override
	public void add(Customer customer) {
		customers.add(customer);
		
	}
	
	public Set<Customer> getCustomers(){
		return customers;
	}
	
	public Set<Customer> getCustomersSortByBirthday(){
		Set<Customer> customerSet = new TreeSet<>(new DateComparator());
		for(Customer customer:customers) {
			customerSet.add(customer);
		}
		return customerSet;
	}

}
